
package com.warmlight.voicepacket.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class VoicePacketDBHelper extends SQLiteOpenHelper {

    private final boolean DEBUG = true;
    private final String TAG = "VoicePacket";

    public static final int VERSION = 1;
    public static final String DATABASE_NAME = "voicepacket.db";
    public static final String _ID = "_id";

    // ----------------------------list-----------------------
    //关联了bean和provider cursor的数据顺序
    public static final String TABLE_LIST = "list";
    public static final String LIST_ID = "list_id";
    public static final String LIST_NAME = "list_name";
    public static final String LIST_IMG_PATH = "list_img_path";
    public static final String LIST_COUNT = "list_count";
    public static final String LIST_AUDIO = "list_audio";
    public static final String LIST_PS = "list_ps";

    // ----------------------------audio----------------------
    //关联了bean和provider cursor的数据顺序
    public static final String TABLE_AUDIO = "audio";
    public static final String AUDIO_ID = "audio_id";
    public static final String AUDIO_TITLE = "audio_title";
    public static final String AUDIO_URL = "audio_url";
    public static final String AUDIO_COVER_ID = "audio_cover_id";
    public static final String AUDIO_PS = "audio_ps";

    private final String CREATE_TABLE_LIST = "CREATE TABLE "
            + TABLE_LIST + " (" + _ID
            + " INTEGER PRIMARY KEY AUTOINCREMENT , " + LIST_ID + " VARCHAR, "
            + LIST_NAME + " VARCHAR, "+ LIST_IMG_PATH + " VARCHAR, " + LIST_COUNT + " VARCHAR, "
            + LIST_AUDIO + " VARCHAR, " + LIST_PS + " VARCHAR )";
    
    private final String CREATE_TABLE_AUDIO = "CREATE TABLE "
            + TABLE_AUDIO + " (" + _ID
            + " INTEGER PRIMARY KEY AUTOINCREMENT , " + AUDIO_ID + " VARCHAR, "
            + AUDIO_TITLE + " VARCHAR, " + AUDIO_URL + " VARCHAR, " + AUDIO_COVER_ID  + " VARCHAR, " + AUDIO_PS + " VARCHAR )";

    public VoicePacketDBHelper(Context context) {
        super(context, DATABASE_NAME, null, VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        if (DEBUG)
//            Log.e(TAG, "Database created!");
        db.execSQL(CREATE_TABLE_LIST);
        db.execSQL(CREATE_TABLE_AUDIO);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        if (DEBUG)
            Log.w(TAG, "Database upgraded!");
//        db.execSQL("DROP TABLE " + CREATE_TABLE_LIST);
//        db.execSQL("DROP TABLE " + CREATE_TABLE_AUDIO);
//        onCreate(db);
    }
    
}
